package com.xmh.code.controller;


import com.xmh.code.service.BusinessService;
import com.xmh.code.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@CrossOrigin
@RequestMapping
@Slf4j
public class PongController {

    private final BusinessService businessService;

    public PongController(BusinessService businessService) {
        this.businessService = businessService;
    }

    @GetMapping("/pong")
    public Mono<ResponseEntity<String>> pong(@RequestParam String data) {
        return ResultUtil.rateLimiterHandle(data, () -> businessService.doSomething(data));
    }
}
